/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.icad.entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Entity
@Table(name = "tipo_documento")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "TipoDocumento.findAll", query = "SELECT t FROM TipoDocumento t"),
    @NamedQuery(name = "TipoDocumento.findByIglesia", query = "SELECT t FROM TipoDocumento t WHERE t.tipoDocumentoPK.iglesia = :iglesia"),
    @NamedQuery(name = "TipoDocumento.findByCodigo", query = "SELECT t FROM TipoDocumento t WHERE t.tipoDocumentoPK.codigo = :codigo"),
    @NamedQuery(name = "TipoDocumento.findByNombre", query = "SELECT t FROM TipoDocumento t WHERE t.nombre = :nombre")})
public class TipoDocumento implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TipoDocumentoPK tipoDocumentoPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "nombre")
    private String nombre;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "tipoDocumento")
    private List<DetalleTransaccion> detalleTransaccionList;
    @JoinColumn(name = "iglesia", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Iglesia iglesia1;

    public TipoDocumento() {
    }

    public TipoDocumento(TipoDocumentoPK tipoDocumentoPK) {
        this.tipoDocumentoPK = tipoDocumentoPK;
    }

    public TipoDocumento(TipoDocumentoPK tipoDocumentoPK, String nombre) {
        this.tipoDocumentoPK = tipoDocumentoPK;
        this.nombre = nombre;
    }

    public TipoDocumento(int iglesia, int codigo) {
        this.tipoDocumentoPK = new TipoDocumentoPK(iglesia, codigo);
    }

    public TipoDocumentoPK getTipoDocumentoPK() {
        return tipoDocumentoPK;
    }

    public void setTipoDocumentoPK(TipoDocumentoPK tipoDocumentoPK) {
        this.tipoDocumentoPK = tipoDocumentoPK;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    @XmlTransient
    public List<DetalleTransaccion> getDetalleTransaccionList() {
        return detalleTransaccionList;
    }

    public void setDetalleTransaccionList(List<DetalleTransaccion> detalleTransaccionList) {
        this.detalleTransaccionList = detalleTransaccionList;
    }

    public Iglesia getIglesia1() {
        return iglesia1;
    }

    public void setIglesia1(Iglesia iglesia1) {
        this.iglesia1 = iglesia1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (tipoDocumentoPK != null ? tipoDocumentoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TipoDocumento)) {
            return false;
        }
        TipoDocumento other = (TipoDocumento) object;
        if ((this.tipoDocumentoPK == null && other.tipoDocumentoPK != null) || (this.tipoDocumentoPK != null && !this.tipoDocumentoPK.equals(other.tipoDocumentoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.icad.entity.TipoDocumento[ tipoDocumentoPK=" + tipoDocumentoPK + " ]";
    }
    
}
